package org.example.bookstore.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.example.bookstore.custom.ResultVO;
import org.example.bookstore.pojo.DO.Comment;
import org.example.bookstore.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "评论Api")
@RestController
@CrossOrigin
@Slf4j
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    private CommentService commentService;

    /*
     * 评论添加
     * */
    @Operation(summary = "添加评论")
    @PutMapping("/add")
    public ResultVO<?> addComment(@RequestBody Comment comment){
        return commentService.addComment(comment);
    }

    /*
     * 评论查询  根据书本id查询所有评论 list(返回用户姓名+头像+评论内容)
     * */
    @Operation(summary = "查询评论列表评论")
    @GetMapping("/list")
    public ResultVO<?> addComment(@Parameter(name = "id", description = "书本id") @RequestParam Integer id){
        return commentService.getCommentList(id);
    }
    /*
     * 根据书本id评论查询总数
     * */
    @Operation(summary = "查询评论总条数")
    @GetMapping("/sum")
    public ResultVO<?> getCommentSum(@Parameter(name = "id", description = "书本id") @RequestParam Integer id){
        return commentService.getCommentSum(id);
    }

    /*
     * 评论修改
     * */

    /*
     * 根据评论id删除评论
     * */
    @Operation(summary = "删除评论")
    @DeleteMapping("/delete")
    public ResultVO<?> deleteCommentSum(@Parameter(name = "id", description = "评论id") @RequestParam Integer id){
        return commentService.deleteComment(id);
    }

}
